1. Field of the Invention
This invention relates to a programmable controller used in sequence control. More particularly, the invention relates to a programmable controller having a user timer (function) employed by the user.
2. Description of the Related Art
A user timer in a programmable controller is realized using a predetermined area (referred to as a "user timer area") in a memory. Specifically, the present value (also referred to as a "counted value") stored in the user timer area is incremented or decremented in order to clock time. (The incrementing or decrementing is also referred to as updating of the present value or updating of the timer). A decision that time has run out is rendered when the present value becomes equal to a predetermined value.
The processing for updating the user timer is executed while referring to a reference clock signal. The reference clock signal is produced by a reference clock generator means incorporated in the programmable controller and, as shown in FIGS. 14 and 15, repeatedly alternates between H and L levels at a fixed period. In FIGS. 14 and 15, the period of the reference clock signal is 200 ms, and the half-period of 100 ms is the minimum unit time for updating the counted value of the timer.
Processing for updating the user timer is executed in the following manner: The state (H level or L level) of the reference clock signal is checked at a predetermined timing. If the state of the signal differs from that which prevailed the last time it was checked, the present value of the user timer is updated. If the state of the reference clock signal is the same as when last checked, a decision is rendered to the effect that updating is unnecessary and therefore the present value of the user timer is not updated.
As will be illustrated later with reference to FIG. 2, the programmable controller repeatedly executes a series of processing operations comprising common processing, user program execution processing and I/O (input/output unit) refresh processing. The time for one cycle of this series of processing operations to be performed is referred to as "cycle time". A timer instruction for starting a predetermined user timer (and for updating the timer in certain cases) is contained in the user program.
The timing at which the state of the reference clock signal is checked in order to update the timer is of two kinds, though the timing differs depending upon the type of programmable controller. Specifically, the state of the reference clock signal is checked
1) when the timer instruction contained in the user program is executed and/or
2) when common processing is executed in each cycle time.
The following problem arises with a programmable controller employing the timer update timing of type 1):
As shown in FIG. 14, if the time interval between the moment at which the immediately preceding timer instruction is executed and the moment at which the current identical timer instruction is executed exceeds the abovementioned minimum unit time (100 ms), the state of the reference clock signal when checked the immediately preceding time will be the same as that when checked at the present time (the state of the signal will be the H level at both times in the illustrated example). Consequently, the timer will not be updated even though a time in excess of the minimum unit time has elapsed. Accordingly, the timekeeping performed by the timer will not be executed correctly.
The following problem arises with a programmable controller employing the timer update timing of type 2):
As shown in FIG. 15, if one cycle time (CT) is less than the minimum unit time (100 ms), then timer update will be performed correctly in dependence upon whether or not there is a change in the state of the reference clock signal, as at update timings 2, 3, 4 and 6. FIG. 15 is a time chart for a decrementing timer (a preset timer); therefore, the present value is decremented. However, if one cycle time (CT) exceeds the minimum unit time, as it does between the update timings 4 and 5, then the state of the reference clock will be the same at the immediately preceding time 4 and at the present time 5 (the state will be the H level at both times). As a result, the timer will not be updated (the decremented value will be zero).
The greater the amount of processing in accordance with the user program, the more frequently these problems arise.
Furthermore, the following problem arises owing to the updating methods 1) and 2) mentioned above:
Reference will be had to FIG. 16 in relation to the update timing of method 1). As shown in FIG. 16, if the initial update timing (when the timer is started) occurs immediately before the leading edge of the reference clock signal and the second update timing occurs immediately after this leading edge, 100 ms is measured despite the fact that the actual elapsed time is very small. As a result, a measurement error of nearly 100 ms occurs at the instant the timer is started.